//
//  HttpService.h
//  aloqa
//
//  Created by mkoo sun on 12-8-24.
//  Copyright (c) 2012年 exodus. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "HttpListener.h"
#import "StateProvider.h"
#import "HttpUtil.h"
#import "SessionListenerDelegate.h"

//-------------------------------------------------------------------------------------------
@class HttpService;

typedef enum _EHttpTaskStatus
{
    TASK_REQUEST = 0,
    TASK_COMPLETED = 1,
    TASK_NEED_RETRY = 2,
}EHttpTaskStatus;

@interface HttpTask : NSObject <HttpDelegate, SessionListenerDelegate>
{
//    id owner;
//    NetHandler* handler;
}

-(void) onSuccess:(int) code  action:(NSString*) aciton message:(NSString*)message;
-(void) onError:(int) code  action:(NSString*) aciton message:(NSString*)message;
-(void) onLogining;
-(void) onLogon:(User*) user;
-(void) onFailedLogin: (int) code message:(NSString*) message;

@property (nonatomic, assign) id owner;
@property (nonatomic, retain) NetHandler* handler;
@property (nonatomic, retain) id<HttpListener> listener;
@property (nonatomic, assign) EHttpTaskStatus status;
@property (nonatomic, assign) int retryTimes;
//@property (atomic, assign) BOOL isCompleted;

@property (nonatomic, retain) NSString* url;
@property (nonatomic, retain) NSString* method;
@property (nonatomic, retain) NSDictionary* header;
@property (nonatomic, retain) NSData* body;
@property (nonatomic, assign) BOOL wait;
@property (nonatomic, retain) NSString* oldSession;

@end

//-------------------------------------------------------------------------------------------
@interface HttpService : NSObject
{
//    public static final String description = "org.exodus.aloqa.http.HTTP";
//    protected ThreadPoolExecutor threadPool;
//	protected Map<Integer, StateProvider> providers;
//	protected ServiceHost host;
//	protected HttpParams params;
    
    NSMutableArray* providers;
    
    //NSDictionary* params;
}

@property (nonatomic, retain) NSMutableArray* httpTaskList;

-(NSString*)getState;

-(void)parseState:(NSString*)content;

-(void)request:(NSString*)url method:(NSString*)method headers:(NSDictionary*)headers body:(NSData*)body listener:(id<HttpListener>)listener wait:(BOOL)wait;

-(int)registerStateProvider:(id<StateProvider>)provider;

-(void)unregisterStateProvider:(int)stub;

-(void)updateUncompleteTask;

@end
